import Vue from 'vue'
import Vuex from 'vuex'
import home from './modules/home'
import user from './modules/user'
import vuextest from './modules/vuextest'
import search from './modules/search'
import detail from './modules/detail'
import shopcart from './modules/shopcart'
import trade from './modules/trade'
import test from './modules/test'
import testspace from './modules/testspace'

// 安装插件
Vue.use(Vuex)

const actions = {}
const mutations = {}
const state = {}
const getters = {}

// 创建并暴露一个store对象
export default new Vuex.Store({
	// 未开启模块化
	state: {
		str: '我爱你'
	},
	mutations: {
		SET_STR(state, str) {
			state.str = str;
		}
	},
	actions: {
		changeStr({ commit }, str) {
			commit('SET_STR', str)
		}
	},
	getters: {
		moreStr(state) {
			return `我的心意:${ state.str }`
		}
	},
	modules:{
		home,
		user,
		vuextest,
		search,
		detail,
		shopcart,
		trade,
		test, // 仅模块化
		testspace, // 开启命名空间
	}
})